package xyz.jcat.biz.admin.service;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import xyz.jcat.biz.admin.BizAdminApplication;
import xyz.jcat.biz.admin.domain.po.RolePo;
import xyz.jcat.biz.admin.domain.po.UserPo;
import xyz.jcat.biz.admin.domain.po.UserRolePo;
import xyz.jcat.common.util.CodeUtils;

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = BizAdminApplication.class)
public class ServiceImpl {

    private static final String USERNAME_ADMIN = "admin";
    @Autowired
    private IUserService userService;
    @Autowired
    private IRoleService roleService;
    @Autowired
    private IUserRoleService userRoleService;

    @Test
    public void test() {
        UserPo adminUser = new UserPo();
        adminUser.setId(1L);
        adminUser.setUsername(USERNAME_ADMIN);
        adminUser.setEmail("empty");
        adminUser.setPhone("empty");
        adminUser.setName("empty");
        adminUser.setPassword(CodeUtils.pwdEncrypt("admin", 6));
        adminUser.setCreator(1L);
        adminUser.setUpdater(1L);
        userService.insert(adminUser);
    }

    @Test
    public void testRole() {
        RolePo role = new RolePo();
        role.setId(1L);
        role.setRoleName("超级管理员");
        role.setRoleType("ADMIN");
        role.setCreator(1L);
        role.setUpdater(1L);
        roleService.insert(role);
    }

    @Test
    public void testUserRole() {
        UserRolePo userRole = new UserRolePo();
        userRole.setUserId(1L);
        userRole.setRoleId(1L);
        userRole.setCreator(1L);
        userRole.setId(1L);
        userRoleService.insert(userRole);
    }

    @Test
    public void testGetUser() {
        System.out.println(userService.getById(1L));
    }
}
